package com.ssy.lingxi.product.entity.customer;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.platform.Category;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 品类实体类--前端客户
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/22
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_customer_category", indexes = {@Index(name = "product_customer_category_member_id_member_role_id_idx", columnList = "memberId,memberRoleId"),
        @Index(name = "product_customer_category_name_idx", columnList = "name"),
        @Index(name = "product_customer_category_type_idx", columnList = "type"),
        @Index(name = "product_customer_category_level_idx", columnList = "level"),
        @Index(name = "product_customer_category_parent_id_idx", columnList = "parentId"),
        @Index(name = "product_customer_category_sort_idx", columnList = "sort")})
public class CustomerCategory implements Serializable {
    private static final long serialVersionUID = -1935846474321224505L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="customer_category_seq")
    @SequenceGenerator(sequenceName="product_customer_category_seq", name="customer_category_seq",allocationSize = 1)
    private Long id;

    /**
     * 品类名称
     */
    @Column(columnDefinition = "varchar(16)", nullable = false)
    private String name;

    /**
     * 品类类型：1-实物商品、2-虚拟商品、3-服务商品、4-积分兑换商品
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer type;

    /**
     * 品类图片url路径
     */
    @Column(columnDefinition = "varchar(250)")
    private String imageUrl;

    /**
     * 级别
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer level;

    /**
     * 品类父id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long parentId;

    /**
     * 完整Id
     */
    @Column(columnDefinition = "varchar(100)", nullable = false)
    private String fullId;

    /**
     * 排序
     */
    @Column(columnDefinition = "int")
    private Integer sort;

    /**
     * 送货周期
     */
    @Column(columnDefinition = "int")
    private Integer sendCycle;

    /**
     * 会员id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberId;

    /**
     * 会员名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberName;

    /**
     * 会员角色id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberRoleId;

    /**
     * 会员角色名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberRoleName;

    /**
     * 用户id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long userId;

    /**
     * 用户名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String userName;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();

    /**
     * 后台品类
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="categoryId",referencedColumnName = "id")
    private Category category;

    /**
     * 品类对应的属性列表
     */
    @JsonManagedReference
    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(name="product_customer_category_attribute",
            joinColumns={ @JoinColumn(name="category_id", referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="attribute_id", referencedColumnName="id")})
    private List<CustomerAttribute> customerAttributeList;

}
